package ysq.xyg.sale.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.sale.model.po.SaleProduct;
import ysq.xyg.sale.model.vo.SaleProductVo;
import ysq.xyg.sale.service.SaleProductService;
import ysq.xyg.sys.model.vo.SysUserVo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 销售模块-销售产品controller层
 *
 * @author shengQiang yu
 * @date 2019-9-9 14:17:04
 */
@RestController
public class SaleProductController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(SaleProductController.class);
    @Resource
    private SaleProductService saleProductService;

    private SaleProduct saleProduct;
    /**
     * 创建产品
     *
     * @param id 商品id
     * @param priceType 套餐类型:1、试用期套餐，2、一年套餐，3、两年套餐，4、三年套餐
     * @param request
     * @return ReturnEntity 对象
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @BaseLog(module = "销售模块",className = "销售产品",methods = "创建产品",businessType = BaseConstant.SYS_BUSINESS_TYPE_INSERT,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleProduct/createProduct",method = RequestMethod.POST)
    public ReturnEntity createProduct(HttpServletRequest request, String id, String priceType){
        ReturnEntity returnEntity = saleProductService.createProduct(request,id,priceType,acceptCurrentUser(request));
        return returnEntity;
    }
    /**
     * 续费产品
     *
     * @param id 商品id
     * @param productMyId 我的续费商品id
     * @param priceType 套餐类型:1、试用期套餐，2、一年套餐，3、两年套餐，4、三年套餐
     * @param request
     * @return ReturnEntity 对象
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @BaseLog(module = "销售模块",className = "销售产品",methods = "续费产品",businessType = BaseConstant.SYS_BUSINESS_TYPE_INSERT,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleProduct/addProduct",method = RequestMethod.POST)
    public ReturnEntity addProduct(HttpServletRequest request, String id, String productMyId,String priceType){
        ReturnEntity returnEntity = saleProductService.addProduct(request,id,priceType,productMyId,acceptCurrentUser(request));
        return returnEntity;
    }
    /**
     * 分页查询
     *
     * @param saleProductVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @BaseLog(module = "销售模块",className = "销售产品",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleProduct/page",method = RequestMethod.POST)
    public ReturnEntity page(SaleProductVo saleProductVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = saleProductService.page(saleProductVo,pageSize,pageNum);
        return returnEntity;
    }
    /**
     * 列表查询
     *
     * @param saleProductVo 对象
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @BaseLog(module = "销售模块",className = "销售产品",methods = "列表查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleProduct/list",method = RequestMethod.POST)
    public ReturnEntity list(SaleProductVo saleProductVo){
        ReturnEntity returnEntity = saleProductService.list(saleProductVo);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @RequestMapping(value = "/saleProduct/saleProductMyBuy",method = RequestMethod.GET)
    public ModelAndView saleProductMyBuy(String id,String productMyId){
        ModelAndView view = new ModelAndView("/sale/saleProductMyBuy");
        saleProduct = saleProductService.selectByPrimaryKey(id);
        view.addObject("saleProduct", saleProduct);
        view.addObject("productMyId", productMyId);
        return view;
    }
    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @RequestMapping(value = "/saleProduct/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id,String page){
        if(StrUtil.isEmpty(page)){
            page="saleProductUpdateOrSave";
        }
        ModelAndView view = new ModelAndView("/sale/"+page);
        if(StrUtil.isNotEmpty(id)){
            saleProduct = saleProductService.selectByPrimaryKey(id);
            view.addObject("saleProduct", saleProduct);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @BaseLog(module = "销售模块",className = "销售产品",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleProduct/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return saleProductService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param saleProductVo Vo对象
     * @author shengQiang yu
     * @date 2019-9-9 14:17:04
     */
    @BaseLog(module = "销售模块",className = "销售产品",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleProduct/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,SaleProductVo saleProductVo){
        return saleProductService.addOrUpdate(saleProductVo,acceptCurrentUser(request));
    }
    /**
     * 获取分类和产品
     *
     * @param saleProductVo 对象
     * @author shengQiang yu
     * @date 2019-3-30 11:24:36
     */
    @BaseLog(module = "销售模块",className = "销售产品", methods = "分类和产品", businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE, operatorType = BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/saleProduct/dTreeList")
    public ReturnEntity dTreeList(SaleProductVo saleProductVo) {
        return saleProductService.dTreeList(saleProductVo);
    }
}